package com.yanfan.parking.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.parking.domain.NjParkingCarInfo;
import com.yanfan.parking.service.INjParkingCarInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 车辆信息Controller
 *
 * @author genluo
 * @date 2024-10-31
 */
@Api(tags = "车辆信息")
@RestController
@RequestMapping("/parking/carInfo")
public class NjParkingCarInfoController extends BaseController {
    @Autowired
    private INjParkingCarInfoService njParkingCarInfoService;

    /**
     * 查询车辆信息列表
     */
    @ApiOperation("车辆信息分页列表")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjParkingCarInfo njParkingCarInfo) {
        startPage();
        List<NjParkingCarInfo> list = njParkingCarInfoService.queryPageList(njParkingCarInfo);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @ApiOperation("导出车辆信息列表")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:export')")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjParkingCarInfo njParkingCarInfo) {
        List<NjParkingCarInfo> list = njParkingCarInfoService.queryPageList(njParkingCarInfo);
        ExcelUtil<NjParkingCarInfo> util = new ExcelUtil<NjParkingCarInfo>(NjParkingCarInfo.class);
        util.exportExcel(response, list, "车辆信息数据");
    }

    /**
     * 获取车辆信息详细信息
     */
    @ApiOperation("获取车辆信息详细信息")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(njParkingCarInfoService.getById(id));
    }

    /**
     * 新增车辆信息
     */
    @ApiOperation("新增车辆信息")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:add')")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjParkingCarInfo njParkingCarInfo) {
        njParkingCarInfo.setCreateTime(DateUtils.getTimestamp());
        return toAjax(njParkingCarInfoService.save(njParkingCarInfo));
    }

    /**
     * 修改车辆信息
     */
    @ApiOperation("修改车辆信息")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:edit')")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjParkingCarInfo njParkingCarInfo) {
        return toAjax(njParkingCarInfoService.updateById(njParkingCarInfo));
    }

    /**
     * 删除车辆信息
     */
    @ApiOperation("删除车辆信息")
    @PreAuthorize("@ss.hasPermi('parking:carInfo:remove')")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(njParkingCarInfoService.removeBatchByIds(Arrays.asList(ids)));
    }
}
